<template>
  <div style="margin: 10px;">
    <el-form style="margin-left: 10px;" ref="form" label-position="top">
      <div>
        <el-form-item label="请选择模型">
          <el-select ref="optionRef" v-model="value" placeholder="请选择" style="width: 100%;"
            :disabled="$route.query.type == 2">
            <el-option v-for="item in modelList" :key="item.modelCode" :label="item.modelName" :value="item.modelCode">
            </el-option>
          </el-select>
        </el-form-item>
      </div>
    </el-form>
    <div style="width: 100%; text-align: center;" v-if="$route.query.type != 2">
      <el-button @click="saveClose" type="primary">保存</el-button>
    </div>
  </div>
</template>

<script>
import { queryDeviceModelList } from "@/api/workflow/index"
export default {
  data () {
    return {
      value: '',
      modelList: []
    }
  },
  props: {
    capList: {
      type: String,
      default: ""
    },
  },
  mounted () {
    if (this.capList) {
      this.value = JSON.parse(this.capList).deviceModelCode
    }
    this.getDeviceModelList()
  },
  methods: {
    async getDeviceModelList () {
      const res = await queryDeviceModelList()
      if (res.status == 200) {
        this.modelList = res.object
      }
    },
    saveClose () {
      this.$emit('addMessage', {
        deviceModelName: this.$refs.optionRef.selected.label,
        deviceModelCode: this.value
      })
    }
  }
}
</script>


<style></style>
